/**
 * @param {number[]} nums
 * @return {number}
 */
var beautifulSubarrays = function (nums) {
  let left = 0,
    right = nums.length,
    count = 0
  for (; left < right - 1; left++) {
    for (; right > left + 1; right--) {
      let arr = nums.slice(left, right)
      if (arr.reduce((pre, cur) => pre ^ cur) == 0) count++
    }
    right = nums.length
  }
  return count
}

beautifulSubarrays([4, 3, 1, 2, 4])
